import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
// import 'package:flutter_application_1/pages/data/home_page_data.dart';
import 'package:flutter_application_1/pages/data/new_data.dart';

// 1.先混入ChangeNotifier，方便ViewModel通知刷新
class HomeViewModel with ChangeNotifier {
  // 2.定义bannerList
  List<NewData>? bannerList;
  Future getBanner() async {
    Dio dio = Dio();
    dio.options = BaseOptions(
      method: 'GET',
      baseUrl: 'https://webapi.ldjyypt.com/',
      connectTimeout: 5000,
      receiveTimeout: 5000,
    );

    Response response = await dio.post(
        'https://webapi.ldjyypt.com/api/News/SelectNewsForHomePage',
        data: {"typeCode": '', "pageSize": 10, 'pageIndex': 1, 'isTop': '1'});
    NewData homePageData = NewData.fromJson(response.data);
    // NewData homePageData = NewData.fromJson(response.data);
    final data = homePageData.data;
    if (data != null) {
      // 3.return 改为 bannerlist 赋值
      bannerList = data.cast<NewData>();
    } else {
      bannerList = [];
    }
    // print('${data}156');
    // 4.值有变化 通知刷新
    notifyListenters() {}
  }
}
